package top.ranzhang.controller.admin;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import top.ranzhang.bean.dto.AddCourseDTO;
import top.ranzhang.bean.dto.UpadteCourseDTO;
import top.ranzhang.bean.vo.AdminCourseVO;
import top.ranzhang.bean.vo.CourseTableVO;
import top.ranzhang.common.result.Result;
import top.ranzhang.service.ICourseService;

/**
 * 课程表
 * @author ranzhang
 * @create 2020-04-08
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/admin/course")
public class CourseController {

    private final ICourseService courseService;

    /**
     * 课程表列表
     * @return
     */
    @GetMapping("/list")
    public Result<CourseTableVO> list() {
        log.info("课程表列表");
        CourseTableVO courseTableVO = courseService.ToList();
        return Result.success(courseTableVO);
    }

    /**
     * 课程表详情
     * @param id
     * @return
     */
    @GetMapping("/getById")
    public Result<AdminCourseVO> getById(Integer id) {
        log.info("课程表详情:{}", id);
        AdminCourseVO adminCourseVO = courseService.ToGetById(id);
        return Result.success(adminCourseVO);
    }

    /**
     * 更新课程表
     * @param upadteCourseDTO
     * @return
     */
    @PutMapping("/update")
    public Result update(@Validated @RequestBody UpadteCourseDTO upadteCourseDTO) {
        courseService.ToUpdate(upadteCourseDTO);
        return Result.success();
    }

    /**
     * 删除课表
     * @param id
     * @return
     */
    @DeleteMapping("/delete/{id}")
    public Result Delete(@PathVariable Integer id) {
        courseService.ToRemove(id);
        return Result.success();
    }

    /**
     * 保存课程表
     * @param addCourseDTO
     * @return
     */
    @PostMapping("/save")
    public Result save(@Validated @RequestBody AddCourseDTO addCourseDTO) {
        courseService.ToSave(addCourseDTO);
        return Result.success();
    }
}
